package Generator;

import Enemies.Enemy;
import Manage.*;
import info.gridworld.grid.*;
import Enemies.*;
public class Generate extends Path{
	//level number
	private static int farthestLevel = 1;
	private static int level = 1;
	private static int creation = 0;
	private static int c = 0;
	private static int multiplier = -2;
	public void act(){
		if (creation < 7){
			if(level % 25 == 0){
				multiplier++;
			}
			Randomize((int) (Math.random() * c));
			c = c + level;
		}
		else{
			if (creation == 13){
				if(level == 50){
					Drago a = new Drago(maze.getPath());
					PlaceObject(a);
				}
				creation = -1;
				level = level + 1;
				if(level > farthestLevel){
					farthestLevel = level;
				}
				c = 0;
			}
		}
		creation ++;
	}
	public static int getRecord(){
		return farthestLevel;
	}
	public static int getLevel(){
		return level;
	}
	public static void reset(){
		c = 0;
		level = 1;
		creation = 0;
	}
	public void Randomize(int create){
		create = create + 1;
		int co;
		if(level == 50){
			//DR. DRAGO!!!!
			
		}else if(level % 10 == 0){
				co = 1;
				for (int x = 0; x < co; x++){
					BossEnemy a = new BossEnemy(maze.getPath());
					a.setStats(multiplier-1);
					PlaceObject(a);
				}
		}else if(level > 50 && level < 53){
			//dont generate anything. bossfight
		}else{
			//if its after level 60, you already killed drago, and there's no point in making more code
			if (create > 1){
				co = (int) (Math.random() * Math.sqrt(c)) + 1;
				for (int x = 0; x < co; x++){
					Enemy a = new Enemy(maze.getPath());
					a.setStats(multiplier);
					PlaceObject(a);
				}
			}
			if (create > 5){
				co = (int) (Math.random() * Math.sqrt(Math.sqrt(c))) + 1;
				for (int x = 0; x < co; x++){
					FastEnemy a = new FastEnemy(maze.getPath());
					a.setStats(multiplier);
					PlaceObject(a);
				}
			}
			if (create > 20){
				co = (int) (Math.random() * Math.sqrt(Math.sqrt(c))) + 1;
				for (int x = 0; x < co; x++){
					SuperFastEnemy a = new SuperFastEnemy(maze.getPath());
					a.setStats(multiplier);
					PlaceObject(a);
				}
			}
			if (create > 50){
				co = (int) (Math.random() * Math.sqrt(Math.sqrt(c))) + 1;
				for (int x = 0; x < co; x++){
					TankEnemy a = new TankEnemy(maze.getPath());
					a.setStats(multiplier);
					PlaceObject(a);
				}
			}
			if (create >= 100){
				co = 1;
				for (int x = 0; x < co; x++){
					BossEnemy a = new BossEnemy(maze.getPath());
					a.setStats(multiplier-1);
					PlaceObject(a);
				}
			}
		}
	}
	public void PlaceObject(Enemy a){
		for (int x = 2; x < getGrid().getNumDep(); x++){
			Location loc = new Location(0,0,x);
			if (getGrid().get(loc) == null){
				a.putSelfInGrid(getGrid(),loc);
				break;
			} 
		}
	}
}
